"""NM64 BIN data format
Copyright (c) 2010-2011 Christian T. Steigies <christian@steigies.net>

This module offers functions to read NM64 BIN files."""

__author__ = "Christian T. Steigies <christian@steigies.net>"
__license__ = "GPL License"

## --------------------------------------------------------------------------

import os

## --------------------------------------------------------------------------

def ReadBIN(filename):
    # read BIN file into chunk
    
    if os.path.exists(filename):
        binsize = os.stat(filename).st_size
        if (binsize) == 3120:
            print "opening %s" % (filename)
            BIN = open(filename, "rb")
            chunk = BIN.read(60*26*2) # 60 Minuten a 26 Worte a 2 byte
            BIN.close()
        else:
            print "file %s is corrupt, size is %i bytes instead of 3120 bytes" %(filename, binsize)
            #exit (1)
            raise IOError
    else:
        print "file not found: %s" % (filename)
        #exit (1)
        raise IOError

    return(chunk)

## --------------------------------------------------------------------------




if __name__=="__main__":
    print "This is a module to work with NM64 BIN files."
